//
//  RootViewController.m
//  A段项目,漫画
//
//  Created by dllo on 15/4/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface RootViewController ()
@property(nonatomic, retain)MainViewController *centerController;
@property(nonatomic, retain)ToolsViewController *leftController;
@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [MidTools shareMidTools].delegate2 = self;
    [self createView];
}
- (void)closeTool{
    [self swipeActionLeft:[[UISwipeGestureRecognizer alloc] init]];
}
- (void)createView{
    //主页面
    self.centerController = [[MainViewController alloc] init];
    [self.centerController.view setFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self addChildViewController:self.centerController];
    [self.view addSubview:self.centerController.view];
    [self.centerController release];
    
    
    //左页面
    self.leftController = [[ToolsViewController alloc] init];
    UINavigationController *leftNA = [[UINavigationController alloc] initWithRootViewController:self.leftController];
    [self.leftController.view setFrame:CGRectMake(-WIDTH, 0, WIDTH, HEIGHT)];
    [self addChildViewController:leftNA];
    [self.view addSubview:self.leftController.view];
    [self.leftController release];
    
    //手势
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeActionRight:)];
    [self.view addGestureRecognizer:swipeRight];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeActionLeft:)];
    [self.view addGestureRecognizer:swipeLeft];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    
}

- (void)swipeActionRight:(UISwipeGestureRecognizer *)swipe{
    [UIView animateWithDuration:0.25 animations:^{
        self.leftController.view.frame = CGRectMake(-WIDTH + 280, 0, WIDTH, HEIGHT);
        self.centerController.view.frame = CGRectMake(280, 0, WIDTH, HEIGHT);
    } completion:^(BOOL finished) {
    }];
}
- (void)swipeActionLeft:(UISwipeGestureRecognizer *)swipe{
    [UIView animateWithDuration:0.25 animations:^{
        self.leftController.view.frame = CGRectMake(-WIDTH, 0, WIDTH, HEIGHT);
        self.centerController.view.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    } completion:^(BOOL finished) {
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
